;(function($){
window.onload = function(){
        //二级菜单
        (function(){
                var subitm = $('.subNav-items');
                subitm.each(function(){
                        var item = $(this).find('li')
                        if(item.length<=6&&item.length>3){
                                item.each(function(index){
                                        if(index>2)return;
                                        $(this).css('marginTop',10)
                                });
                        }else if(item.length<=3){
                                item.each(function(index){
                                        if(index>2)return;
                                        $(this).css('marginTop',25)
                                });
                        }
                });
        })();

        //大轮播图
        var banner = new Swiper('.swiper-container',{
                width:window.innerWidth,
                height:400,
                autoplay:5000,
                loop:true,
                simulateTouch:false,
                pagination:'.swiper-pagination',
                nextButton:'.btn-swiper1',
                prevButton:'.btn-swiper2',
                onInit : function(swiper){
                        $('.swiper-container img').each(function(index){
                                var winW = window.innerWidth;
                                var imgW = this.offsetWidth;
                                var offW = (winW-imgW)/2;
                                $(this).css('left',offW);
                        });
                        if(navigator.userAgent.match('MSIE 9')){
                                swiper.stopAutoplay();
                                var getAuto = setInterval(function(){
                                        slidAni(false);
                                },5000);
                                $('.btn-swiper1').unbind('click');
                                $('.btn-swiper2').unbind('click');
                                $('.btn-swiper1').click(function(){
                                        slidAni(true);
                                });
                                $('.btn-swiper2').click(function(){
                                        slidAni(false);
                                });
                                var slidAni = (function(){
                                        var isAni = false;
                                        var nowSli = 0;
                                        var slidBox = $('.swiper-container').find('.swiper-wrapper').eq(0);
                                        var sliders = slidBox.find('li');
                                        var num = sliders.length;
                                        return function(index){
                                                var pagins = $('.swiper-container').find('.swiper-pagination span');
                                                if(isAni)return;
                                                isAni = true;
                                                //var offLen = index ? (0-sliders.eq(0).width()) : sliders.eq(0).width();
                                                var offLen = sliders.eq(0).width();
                                                index ? nowSli-- : nowSli++;
                                                if(nowSli>1){
                                                        slidBox.css('left',(0-num+3)*offLen);
                                                        nowSli = 4-num;
                                                        //alert(1)
                                                }else if(nowSli<(0-num+2)){
                                                        slidBox.css('left',0);
                                                        nowSli = -1;
                                                        //alert(2)
                                                }
                                                pagins.each(function(index){
                                                        $(this).removeClass('swiper-pagination-bullet-active');
                                                });
                                                pagins.eq(nowSli).addClass('swiper-pagination-bullet-active');
                                                //pagins.eq(nowSli).addClass('swiper-pagination-bullet-active');
                                                slidBox.animate({'left':nowSli*offLen},500,function(){
                                                        isAni = false;
                                                });
                                        };
                                })();
                        }
                }
        });

        //底部轮播图
        var loopimg = new Swiper('.content-loopimg',{
                width:800,
                height:150,
                autoplay:4000,
                loop:true,
                nextButton:'.btn-loopimg1',
                prevButton:'.btn-loopimg2',
                onInit : function(swiper){
                        if(navigator.userAgent.match('MSIE 9')){
                                swiper.stopAutoplay();
                                var getAuto = setInterval(function(){
                                        slidAni(false);
                                },5000);
                                $('.btn-loopimg1').unbind('click');
                                $('.btn-loopimg2').unbind('click');
                                $('.btn-loopimg1').click(function(){
                                        slidAni(true);
                                });
                                $('.btn-loopimg2').click(function(){
                                        slidAni(false);
                                });
                                var slidAni = (function(){
                                        var isAni = false;
                                        var nowSli = 0;
                                        var slidBox = $('.content-loopimg').find('.swiper-wrapper').eq(0);
                                        var sliders = slidBox.find('li');
                                        var num = sliders.length;
                                        return function(index){
                                                var pagins = $('.content-loopimg').find('.swiper-pagination span');
                                                if(isAni)return;
                                                isAni = true;
                                                //var offLen = index ? (0-sliders.eq(0).width()) : sliders.eq(0).width();
                                                var offLen = sliders.eq(0).width();
                                                index ? nowSli-- : nowSli++;
                                                if(nowSli>1){
                                                        slidBox.css('left',(0-num+3)*offLen);
                                                        nowSli = 4-num;
                                                        //alert(1)
                                                }else if(nowSli<(0-num+2)){
                                                        slidBox.css('left',0);
                                                        nowSli = -1;
                                                        //alert(2)
                                                }
                                                pagins.each(function(index){
                                                        $(this).removeClass('swiper-pagination-bullet-active');
                                                });
                                                pagins.eq(nowSli).addClass('swiper-pagination-bullet-active');
                                                //pagins.eq(nowSli).addClass('swiper-pagination-bullet-active');
                                                slidBox.animate({'left':nowSli*offLen},500,function(){
                                                        isAni = false;
                                                });
                                        };
                                })();
                        }
                }
        });
        //公告栏
        (function(){
                var noticeWrap = $('.notice-wrap').eq(0);
                var closeBtn = $('.notice-close').eq(0);
                closeBtn.click(function(e){
                        noticeWrap.slideUp(500);
                });
        })();
        //新闻资讯
        (function(){
                var tabBtn = $('.content-new-optitem');
                var showCon  = $('.content-new-main-txt');
                tabBtn.each(function(index){
                        var _index = index;
                        $(this).mouseover(function(){
                                showCon.show();
                                showCon.eq(_index).hide();
                                tabBtn.removeClass('active');
                                $(this).addClass('active');
                        });
                });
        })();
};     
})(jQuery);